<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String ctxPath = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ ctxPath + "/";
	String SYSTEM_NAME = "EZMES";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base id="baseUrl" href="<%=basePath%>"/>
    
    <title><%=SYSTEM_NAME%></title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link href="<%=basePath %>css/plugins/ztree/zTreeStyle/zTreeStyle.css" rel="stylesheet">
  </head>
  
  <body>
    <ul id="wrTree" class="ztree"></ul>
    <div style="text-align: center;">
    	<input type="button" onclick="submitForm2()" value="提交">
    </div>
  </body>
    <script src="<%=basePath %>js/jquery-2.1.1.min.js"></script>
	<script src="<%=basePath%>js/plugins/ztree/js/jquery.ztree.core-3.5.min.js"></script>
	<script src="<%=basePath%>js/plugins/ztree/js/jquery.ztree.excheck-3.5.min.js"></script>
	<script src="<%=basePath%>js/plugins/ztree/js/jquery.ztree.exedit-3.5.min.js"></script>
	<!-- <script src="<%=basePath %>js/plugins/layer/layer.js"></script> -->
</html>
<script>
var setting = {
		check: {
			enable: true
		},
		data: {
			simpleData: {
				enable: true
			}
		}
	};
$(function(){
	bindWrTree();
});
function bindWrTree(){
	$.ajax({
		type:'post',
		url:$('#baseUrl').attr("href")+'role/query_rolePermissonsZtreeData?role.r_id='+parent.layer.rid,
		data:"",
		timeout: 50000,
		cache: false,
		async: false,
		success: function(json){
			console.log(json)
			zWrMgrTreeNodes =   eval('('+json + ')');
			//zWrMgrTreeNodes = eval("[" + json + "]");
			//zWrMgrTreeNodes = json.treeData;
			setting.check.chkboxType = { "Y" : "s", "N" : "p" };
			$.fn.zTree.init($("#wrTree"), setting, zWrMgrTreeNodes);
		}
	});
}
function submitForm2(){
	var checkedNode = $.fn.zTree.getZTreeObj("wrTree").getCheckedNodes();
	var rid = parent.layer.rid;
	var nids = [];
	$.each(checkedNode,function(m,n){
		nids.push(n.id);
	});
	$.ajax({
		type:'post',
		url :$('#baseUrl').attr("href")+'role/update_rolePermission',
		data:{"role.r_id":rid,"nids":nids.toString()},
		success:function(data){
			if(data){
				var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
			    parent.layer.close(index);
			}
		}
	});
}
</script>
